package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.dto.PieCountDto;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersIllness;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskPapersIllnessMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersIllnessService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/28 8:56
 */
@Service
public class AIRiskPapersIllnessServiceImpl extends BaseServiceImpl<AIRiskPapersIllnessMapper, AIRiskPapersIllness> implements AIRiskPapersIllnessService {

    @Override
    public List<AIRiskPapersIllness> getByPapersId(Integer id) {
        LambdaQueryWrapper<AIRiskPapersIllness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIllness::getPaperId, id);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<AIRiskPapersIllness> getNotAnswerByPapersId(Integer id) {
        LambdaQueryWrapper<AIRiskPapersIllness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIllness::getPaperId, id);
        queryWrapper.eq(AIRiskPapersIllness::getIsAnswer, false);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> getCountByDisLevel(Integer paperId) {
        return baseMapper.getCountByDisLevel(paperId);
    }

    @Override
    public List<AIRiskPapersIllness> getByHighRiskPapersId(Integer id) {
        LambdaQueryWrapper<AIRiskPapersIllness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIllness::getPaperId, id);
        queryWrapper.eq(AIRiskPapersIllness::getIsAnswer, Boolean.TRUE);
        queryWrapper.orderByDesc(AIRiskPapersIllness::getRiskScore);
        queryWrapper.last(" limit 5");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<PieCountDto> getPieCount() {
        return baseMapper.getPieCount();
    }

    @Override
    public Object getBarCount(String name) {
        Map<String, Object> map = new HashMap<>();
        List<String> xData = new ArrayList<>();
        List<Integer> yData = new ArrayList<>();
        for (PieCountDto pieCountDto : baseMapper.getBarCount(name)) {
            xData.add(pieCountDto.getName());
            yData.add(pieCountDto.getValue());
        }
        map.put("xAxisData", xData);
        map.put("seriesData", yData);
        return map;
    }

    @Override
    public Integer getNotAnswerByPapersIdCount(Integer id) {
        LambdaQueryWrapper<AIRiskPapersIllness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AIRiskPapersIllness::getPaperId, id);
        queryWrapper.eq(AIRiskPapersIllness::getIsAnswer, false);
        return baseMapper.selectCount(queryWrapper);
    }
}
